<?php
  define( 'DEBUG', true );
  $page_url = '/?page_id=4';

  if ( $_GET['spec'] ) {
      $test_action = 'setchoose';
  }
  if ( isset( $_GET['final'] ) ) {
      $test_action = 'final';
  } else
  if ( isset( $_GET['test'] ) ) {
      $test_action = 'test';
  }
  if ( !$test_action || isset( $_GET['choose'] ) ) {
      $test_action = 'choose';
  }
  if ( DEBUG ) {
      echo '$test_action=' . $test_action;
  }
  require_once 'Test.class.php';
  require_once 'Task.class.php';
  switch ( $test_action ) {
      case 'choose':
          require_once dirname( __FILE__ ) . '/data.php';
          require_once dirname( __FILE__ ) . '/choose.template.php';
          break;
      case 'setchoose':
          $test = new Test();
          $test->getRandom( $_GET['spec'] );
          $_SESSION['test'] = $test->getJson();
          $page_url .= '&test';
          ?>
          <script>
              window.location.href = "<?php echo $page_url ?> ";
          </script>
          Re Location : <?php echo $page_url ?>
          <?php
          break;
      case 'test':
          $test = new Test();
          $test->setJson( $_SESSION['test'] );
          require_once dirname( __FILE__ ) . '/test.template.php';
          break;
      case 'final':
          
          $test = new Test();
          $test->setJson( $_SESSION['test'] );
          $test->setAnswers( $_REQUEST['answer'] );
          require_once dirname( __FILE__ ) . '/final.template.php';
          break;
  }
?>